package com.edu.common.utils;

import java.io.IOException;

/**
 * @program: xxxx_4
 * @description:
 * @author: zlh
 * @create: 2024-03-08 15:19
 **/
public class VideoGenerator {

  public static void generateCover(String videoPath, String coverPath) throws Exception {
    // 构建ffmpeg命令
    ProcessBuilder processBuilder = new ProcessBuilder(
        "ffmpeg", "-i", videoPath, "-ss", "00:00:01", "-vframes", "1", coverPath);

      // 启动进程
      Process process = processBuilder.start();

      // 等待ffmpeg命令执行完成
      int exitCode = process.waitFor();

      // 检查是否成功执行
      if (exitCode == 0) {
        System.out.println("Thumbnail generated successfully!");
      } else {
        System.err.println("An error occurred while generating the thumbnail.");
      }

  }
}
